﻿using CompanyManageSystem.DLL;
using CompanyManageSystem.Model;
using CompanyManageSystem.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CompanyManageSystem.UI.Repast
{
    public partial class Frm_PurchaseStorageDetail : BaseXtraForm
    {
        List<PurchaseStorageOrder> ListOrder;

        public Frm_PurchaseStorageDetail()
        {
            InitializeComponent();
            this.BindRowIndicator(gridView1);

            ListOrder = new List<PurchaseStorageOrder>();
        }

        /// <summary>
        /// 窗体加载完成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_PurchaseStorageDetail_Load(object sender, EventArgs e)
        {
            RepastService rservice = new RepastService();
            repositoryItemSearchLookUpEdit1.DataSource = rservice.GetAllMaterial();
            SupplierTree.Properties.DataSource = rservice.GetAllSuppliers();
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.ExportToExcel(gridControl1);
        }

        /// <summary>
        /// 添加GridControl数据方法
        /// </summary>
        /// <param name="header">主单列</param>
        /// <param name="isExcel">是否导出Excel</param>
        public void SetGridControlValue(List<PurchaseStorageOrder> header, bool isExcel)
        {
            RepastService rservice = new RepastService();
            gridControl1.DataSource = rservice.GetPurchaseStorageDetailByHeader(header);

            if (isExcel)
            {
                ExportToExcel(gridControl1);
            }

            this.ListOrder = header;
        }

        /// <summary>
        /// 查找
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Find_Click(object sender, EventArgs e)
        {
            var date1 = dateEdit1.DateTime;
            var date2 = dateEdit2.DateTime;
            var date3 = dateEdit3.DateTime;
            var date4 = dateEdit4.DateTime;
            Guid? supplierId = null;
            if (!string.IsNullOrEmpty(SupplierTree.EditValue.ToString()))
            {
                supplierId = (Guid)SupplierTree.EditValue;
            }
            var style = "";
            if (!string.IsNullOrEmpty(Style.Text))
            {
                style = Style.Text;
            }
            var orderNum = OrderNum.Text;

            var headerId = this.ListOrder.Select(p => p.ID).ToArray();

            RepastService rservice = new RepastService();
            gridControl1.DataSource = rservice.GetStorageDetailByFactor(headerId, date1, date2, date3, date4, supplierId, style, orderNum);
        }

    }
}
